package com.example.logintest.service.impl;

import cn.hutool.core.util.ArrayUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.logintest.mapper.UserMapper;
import com.example.logintest.pojo.User;
import com.example.logintest.service.IUserService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;


/**
 * @Author: Lemon
 * @Description: TODO
 * @Date: 2024/2/18 15:20
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    private static Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
    @Autowired
    private UserMapper userMapper;

    /**
     * 判断用户名
     * @param user
     * @return
     */
    @Override
    public User findByUsername(User user){
        return userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getUsername,user.getUsername()));
    }

    @Override
    public User findUserById(String userId) {
        return userMapper.selectById(userId);
    }

    @Override
    public void addUser(User user) {
        UUID uuid = UUID.randomUUID();
        String id = uuid.toString().replace("-", "").toLowerCase();
        user.setId(id);
        logger.info("id:"+id);
        logger.info("username:"+user.getUsername());
        logger.info("password:"+user.getPassword());

        userMapper.insert(user);
    }
}
